package com.andnnl.fileanalysis;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.exception.ExcelAnalysisException;

import java.io.InputStream;

/**
 * excel解析类
 * Created by chenss on 2021/6/2.
 */
public class XlsAnalysis extends AbsFileAnalysis {

    public XlsAnalysis(){

    }
    @Override
    public void analysis(InputStream is, AnalysisListenerBase listener, AnalysisParam param) {
        AnalysisEventListener xlsListener=new ExcelListenerNew(this,listener,param);
        try {
//            EasyExcelFactory.readBySax(is, new Sheet(1, 0), xlsListener);
//            EasyExcelFactory.read(is, new Sheet(1, 0), xlsListener);
            // easyExcel设置了删除头部行
            EasyExcel.read(is, xlsListener).sheet().headRowNumber(param.getDelHeadRows()).doRead();
        } catch (Exception e) {
            if (e.getMessage().indexOf("interrupt error")!=-1) {
                throw new ReadInterruptException(e);//手动中断
            }
            throw e;
        } finally {
            xlsListener.doAfterAllAnalysed(null);
        }
    }

}
